package com.peak.distribution.entity.agent;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.google.common.collect.Sets;
import com.peak.distribution.enums.Constants;
import com.peak.spring.boot.api.entity.DefaultStategyEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_agent_team")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisAgentTeam extends DefaultStategyEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 团队名称 */
	private String name;
	
	/** 队长 */
	private DisAgent leader;
	
	/** 成员 */
	private Set<DisAgent> members = Sets.newHashSet();

	@ManyToOne
	@JoinColumn(name = "leader_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgent getLeader() {
		return leader;
	}

	@ManyToMany
	@JoinTable(name = "dis_mm_team_agent",
				joinColumns = {@JoinColumn(name = "team_id", referencedColumnName = "id") },
				inverseJoinColumns = {@JoinColumn(name = "agent_id", referencedColumnName = "id") })
	@Fetch(FetchMode.SELECT)
	@LazyCollection(LazyCollectionOption.TRUE)
	public Set<DisAgent> getMembers() {
		return members;
	}
}
